//
//  MailMainTableViewCell.m
//  EpointFrame5
//
//  Created by Pill Gong on 14-1-27.
//  Copyright (c) 2014年 Epoint. All rights reserved.
//

#import "MailMainTableViewCell.h"
#import "UIView+Addtions.h"
#import "EpointConsts.h"


@implementation MailMainTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.leftImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        if (ISIOS7) {
            [self addSubview:_leftImageView];
        } else {
            [self.contentView addSubview:_leftImageView];
        }
        
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        if (ISIOS7) {
            [self addSubview:_titleLabel];
        } else {
            [self.contentView addSubview:_titleLabel];
        }

        self.tipsLabel = [UILabel.alloc initWithFrame:CGRectZero];
        [self addSubview:_tipsLabel];
        
        [self setDeafultValue];
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
    [super setSelected:highlighted animated:animated];
    if (highlighted) {
        if (ISIOS7) {
            _titleLabel.textColor = [UIColor whiteColor];
            _tipsLabel.backgroundColor = [UIColor whiteColor];
            _tipsLabel.textColor = MailCtrlColorGray;
        } else {
            _titleLabel.textColor = [UIColor whiteColor];
            _tipsLabel.backgroundColor = [UIColor whiteColor];
            _tipsLabel.textColor = MailCtrlColorBlue;
        }
    } else {
        _titleLabel.textColor = [UIColor blackColor];
        _tipsLabel.backgroundColor = [UIColor darkGrayColor];
        _tipsLabel.textColor = [UIColor whiteColor];
    }
}

- (void)setDeafultValue {
    _titleLabel.textAlignment = NSTextAlignmentLeft;
    _titleLabel.backgroundColor = [UIColor clearColor];
    
    _tipsLabel.textAlignment = NSTextAlignmentCenter;
    _tipsLabel.layer.cornerRadius = 9;
    _tipsLabel.backgroundColor = [UIColor darkGrayColor];
    _tipsLabel.textColor = [UIColor whiteColor];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    _leftImageView.top = (self.height - _leftImageView.height)*0.5;
    _leftImageView.left = _leftImageView.top;
    if (!ISIOS7) {
        _leftImageView.left += 5;
    }
    
    [_titleLabel sizeToFit];
    _titleLabel.width = AppWidth - _leftImageView.right -10;
    _titleLabel.left = _leftImageView.right+_leftImageView.top;
    _titleLabel.centerY = _leftImageView.centerY;
    
    [_tipsLabel sizeToFit];
    //_tipsLabel.width += 12;
    _tipsLabel.width = _tipsLabel.width>32 ? _tipsLabel.width+12 : 32;
    if (self.accessoryType == UITableViewCellAccessoryNone) {
        _tipsLabel.left = AppWidth - _tipsLabel.width - 10;
    } else {
        if (ISIOS7) {
            _tipsLabel.left = AppWidth - _tipsLabel.width - AccessoryWidth;
        } else {
            if (CurrentDeviceISiPad) {
                _tipsLabel.left = AppWidth - _tipsLabel.width - 2*AccessoryWidth;
            } else {
                _tipsLabel.left = AppWidth - _tipsLabel.width - AccessoryWidth;
            }
        }
    }
    _tipsLabel.centerY = _leftImageView.centerY;
}

@end
